//
//  BrokerManageVc.m
//  WGFGlobalHouses
//
//  Created by welldone on 15/5/20.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "BrokerManageVc.h"
#import "AcitonBayStyleTitleView.h"
#import "config.h"
#import "SearchView.h"
#import "ScroDeleteTableView.h"
#import "BrokerCell.h"
#import "NodataCell.h"
#import "BrokerAddVc.h"

#import "BrokerDM.h"
#import "BorkerCellModel.h"
#import "MJRefresh.h"
#import "UserModal.h"
#import "FooterMenuView.h"
#import "MBProgressHUD+MJ.h"

#import "SelecteStoreVc.h"
#import "EditBrokerVC.h"
#import "StringTool.h"

#import "MBProgressHUD+MJ.h"
#import "HideTextVeiw.h"




typedef enum
{
    selectAllBtn = 1, //全选
    moveBtn = 2,//移动
    beAbleBtn = 3,//启用
    beUnAbleBtn = 4//禁用
}BTNTYPE;

@interface BrokerManageVc ()<UITableViewDataSource,UITableViewDelegate,SearchViewDelegate,FooterMenuViewDelegate,BrokerCellDelegate,UITextFieldDelegate,UITextViewDelegate,ScroDeleteTableViewDelgate>

@property (weak, nonatomic) IBOutlet UITextField *seachField;


@property (weak, nonatomic) IBOutlet UIView *contentView;

@property (nonatomic,strong)ScroDeleteTableView *mainTableView;

@property (nonatomic,strong) AcitonBayStyleTitleView *titleView;

@property (nonatomic,strong) SearchView *seachView;

@property (nonatomic,strong)NodataCell *nodataCell;

@property (nonatomic,strong)NSMutableArray *dataArray,*seachDataArray;


@property (strong, nonatomic) BrokerDM *dataMange;
@property (nonatomic,assign) Boolean isEditMode;


@property(nonatomic,assign) Boolean isSeletedAll; // 是否全部选中
@property (nonatomic,strong) FooterMenuView *footerView;
@property (nonatomic,assign) BTNTYPE btnType;

@property (nonatomic,assign)NSInteger pageIndex;//非搜索情况的页码
@property (nonatomic,assign)NSInteger searchIndex;//搜索情况下的页码

@property (nonatomic,copy)NSString *keyword;//关键字
@property (nonatomic,assign)BOOL isSearchType;//是否是搜索模式

@property (weak, nonatomic) IBOutlet UIButton *cacelBtn;

@property (weak, nonatomic) IBOutlet HideTextVeiw *searchTv;
@property (nonatomic,assign)NSInteger falg;//表示是不是跳转之回到之前的界面，falg = 0不是，>0表示是


@end

@implementation BrokerManageVc
@synthesize titleView,seachView,contentView,mainTableView,dataArray,seachDataArray,nodataCell,dataMange,isEditMode,footerView;


-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
     [self initView];
    self.falg = 0;
    
}


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self refreshData];
    
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.searchTv resignFirstResponder ];
}

-(void)initView{
    [super initView];
    [self.searchTv setHideText:@"可通过经纪人姓名搜索"];
    
    
    [self.cacelBtn setTitle:@"" forState:UIControlStateNormal];
    self.cacelBtn.enabled = NO;
    
    dataMange = [[BrokerDM alloc]init];
    self.btnType = 0;
    
    titleView = [AcitonBayStyleTitleView creadView];
    
    titleView.abackBtn.hidden = self.isHidden;
    titleView.abackBtn.enabled = !self.isHidden;
    [[titleView abackBtn]addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
    [[titleView aeditBtn]addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
    [[titleView aaddBtn]addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
    [[titleView atitleLab]setText:@"经纪人管理"];
    
    [self.seachField setLeftViewMode:UITextFieldViewModeAlways];
    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 38, 44)];
    
    UIImageView *leftView = [[UIImageView alloc]initWithFrame:CGRectMake(backView.frame.size.width/2-8, backView.frame.size.height/2-8, 15, 15)];
    [leftView setImage:[UIImage imageNamed:@"search_icom"]];
    [backView addSubview:leftView];
    [self.seachField setLeftView:backView];
    self.seachField.delegate = self;
    
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:titleView];
    
    
    mainTableView = [[ScroDeleteTableView alloc]initWithFrame:CGRectMake(0, 0, PMW,PMH - 64 - 40 + 17 ) style:UITableViewStylePlain];
    mainTableView.menuStatedelegate = self;
    [contentView addSubview:mainTableView];

    self.mainTableView.delegate =self;
    self.mainTableView.dataSource = self;
    
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, PMW, 15)];
    [headView setBackgroundColor:UIColorFromRGB(0xf3f3f3)];
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, headView.frame.size.height-1, headView.frame.size.width, 1)];
    [line setBackgroundColor:UIColorFromRGB(0xe3e3e3)];
    [headView addSubview:line];
    [self.mainTableView setTableHeaderView:headView];
    
    if (isIOS7) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    if (isIOS7) {
        if ([self.mainTableView respondsToSelector:@selector(setSeparatorInset:)]) {
            [self.mainTableView setSeparatorInset:UIEdgeInsetsZero];
        }
    }
    self.mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    
    seachView = [[SearchView alloc]initWithParentView:self.mainTableView withEt:self.seachField];
    [seachView.tableView addLegendFooterWithRefreshingTarget:self refreshingAction:@selector(searchLoadMore)];
    seachView.delegate = self;
    seachView.textView = self.searchTv;
    
    
    [self.mainTableView addLegendHeaderWithRefreshingTarget:self refreshingAction:@selector(refreshData)];
    [self.mainTableView addLegendFooterWithRefreshingTarget:self refreshingAction:@selector(loadMore)];
    
    
    footerView = [FooterMenuView creatView];
    footerView.delegate = self;
    [self.view addSubview:footerView];
    [footerView setHidden:YES];
}

#pragma mark 搜索情况下刷新数据
-(void)searchRefreshData
{
    self.searchIndex = 1;
    [self.seachView.tableView.footer resetNoMoreData];
    __weak typeof(self) bself = self;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        ResulteMod *resultMod  = [dataMange refreshDataWithStoreCode:@"" withKeyWord:self.keyword];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            if (resultMod.resltState==ResultNetError) {
                
                [MBProgressHUD showError:@"网络错误"];
                
            }else if (resultMod.resltState==ResultFail){
                
                [MBProgressHUD showError:resultMod.resultTip];
                
            }else{
                bself.seachDataArray = [[ NSMutableArray alloc]initWithArray:resultMod.dataMod];
                  [seachView.tableView reloadData];
                [seachView tableViewReloadAndUpFrame];
                bself.searchIndex = (bself.seachDataArray == 0||bself.seachDataArray == nil)?1:2;
            }
            
        });
    });
}

#pragma mark 非搜索模式下，刷新数据
-(void)refreshData{
    
    self.pageIndex = 1;
    [self.mainTableView reloadData];
    [self.mainTableView.footer resetNoMoreData];
    
    [nodataCell setState:nodataCellStateLoading];
    __weak typeof(self) bself = self;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    
       bself.keyword = @"*";
        ResulteMod *resultMod  = [dataMange refreshDataWithStoreCode:@"" withKeyWord:self.keyword];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            if (resultMod.resltState==ResultNetError) {
                
                [bself.nodataCell setState:nodataCellStateNetError];
                
            }else if (resultMod.resltState==ResultFail){
                
                [bself.nodataCell setCodeErrorTip:resultMod.resultCode];
                
            }else{
                
                     bself.dataArray = [[ NSMutableArray alloc]initWithArray:resultMod.dataMod];
                    if (bself.dataArray.count == 0 || bself.dataArray == nil ) {
                        [bself.nodataCell setState:nodataCellStateNodata];
                    }
                [bself.mainTableView.header endRefreshing];
                
               
                
                bself.pageIndex = (bself.dataArray.count == 0 || bself.dataArray == nil)?1:2;
            }
            
             [bself.mainTableView reloadData];
        });
    });
    
}


#pragma mark 搜索情况下，加载更多
-(void)searchLoadMore
{
    __weak typeof(self) bself = self;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
     ResulteMod *resultMod  = [dataMange loadMoreDataWithKeyword:self.keyword withIndex:bself.searchIndex];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [bself.seachView.tableView.footer endRefreshing];
            
            if (resultMod.resltState==ResultNetError) {
                
                [MBProgressHUD showError:@"网络错误"];
                
            }else if (resultMod.resltState==ResultFail){
                
                [MBProgressHUD showError:resultMod.resultTip];
                
            }else{

                    NSArray *searchArr = [NSArray arrayWithArray:resultMod.dataMod];
                    if (searchArr.count == 0 || searchArr == nil) {
                        [bself.seachView.tableView.footer noticeNoMoreData];
                    }else
                    {
                        bself.searchIndex ++;
                    }
                    [bself.seachDataArray addObjectsFromArray:searchArr];
                    [seachView tableViewReloadAndUpFrame];
                    [bself.seachView.tableView reloadData];
            }
            
        });
    });

}
#pragma mark 非搜索模式下，加载更多
-(void)loadMore
{
    
    [self.mainTableView reloadData];
    
    [self.mainTableView.footer resetNoMoreData];
    [nodataCell setState:nodataCellStateLoading];
    __weak typeof(self) bself = self;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            bself.keyword = @"*";
        ResulteMod *resultMod  = [dataMange loadMoreDataWithKeyword:self.keyword withIndex:bself.pageIndex];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [bself.mainTableView.footer endRefreshing];

           
            if (resultMod.resltState==ResultNetError) {
                
                [bself.nodataCell setState:nodataCellStateNetError];
                
            }else if (resultMod.resltState==ResultFail){
                
                [bself.nodataCell setCodeErrorTip:resultMod.resultCode];
                
            }else{
                
                   NSArray *dataArr = [NSArray arrayWithArray:resultMod.dataMod];
                    [bself.dataArray addObjectsFromArray:resultMod.dataMod];
                    
                    if (dataArr.count == 0)
                    {
                        
                        [bself.mainTableView.footer noticeNoMoreData];
                    }else
                    {
                        bself.pageIndex ++;
                    }
            }
           
            [bself.mainTableView reloadData];
      });
    });
    
}


-(void)btnOnclick:(UIButton*)sender{
    
    if (sender==titleView.abackBtn) {
        [self.navigationController popViewControllerAnimated:YES];
    }else if (sender==titleView.aeditBtn){
        
        if (dataArray.count == 0|| dataArray == nil) {
            return;
        }
        [self.seachField resignFirstResponder];
        
        [seachView hide];
        
        self.isEditMode = !self.isEditMode;
        [self.mainTableView reloadData];
        
        if (self.isEditMode) {
            [footerView setHidden:false];
        }else{
            [footerView setHidden:YES];
        }
        
    }else if (sender==titleView.aaddBtn){
        BrokerAddVc *vc = [BrokerAddVc new];
         vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
        
    }else if (sender==nodataCell.refreshBtn){
        
        [self refreshData];
    }
}





#pragma mark tableView delegate

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (dataArray.count==0) {
        return tableView.frame.size.height;
    }
    
    return  [BrokerCell getHight:nil withTableView:tableView];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (dataArray.count==0) {
        [tableView setScrollEnabled:false];
        return 1;
    }
    
    [tableView setScrollEnabled:YES];
    return dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if (dataArray.count==0) {
        if(!nodataCell){
            nodataCell = [[NodataCell alloc] initWithFrame:tableView.frame];
            [nodataCell setState:nodataCellStateLoading];
            [[nodataCell refreshBtn]setTag:56];
            [nodataCell.refreshBtn addTarget:self action:@selector(btnOnclick:) forControlEvents:UIControlEventTouchUpInside];
        }
        return nodataCell;
    }
    
    
    
    static NSString *ID = @"BrokerCell";
    BrokerCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil)
    {
        cell = [[BrokerCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        
        [cell.contentMoveView addTarget:self action:@selector(cellOnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [cell initWithTableView:self.mainTableView];
    }
    
    BorkerCellModel *data = [dataArray objectAtIndex:indexPath.row];
    
    
    [cell.contentMoveView setTag:indexPath.row];
    
    [cell setIsEditMode:self.isEditMode];
    
    cell.data = data;
    cell.btnDelegate = self;
    
    return cell;
    
}


-(void)cellOnClick:(UIButton*)sender{
    
    if (!self.isEditMode) {
        return;
    }
    
    BorkerCellModel *data = [dataArray objectAtIndex:sender.tag];
    
    [data setIsSelected:!data.isSelected];
    
    [self.mainTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:sender.tag inSection:0]] withRowAnimation:UITableViewRowAnimationFade];

    if ([data isSelected]==false) {
        
        [[footerView selectAllBtn] setHighlighted:false];
        [footerView setIsSelectedAllFlag:false];
    }

}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (dataArray.count==0) {
        return;
    }
}


#pragma mark seachView delegate
-(NSArray*)getDataByKewWord:(NSString*)kewWord{
    
    return seachDataArray;
}


-(CGFloat)getCellHight{
    
    return 60;
}

-(NSInteger)getCellCount{
    
    return seachDataArray.count;
}

-(UITableViewCell*)getCellByTableView:(UITableView *)tableView WithIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *ID = @"BrokerCell";
    BrokerCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil)
    {
        cell = [[BrokerCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        
        [cell.contentMoveView addTarget:self action:@selector(cellOnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [cell initWithTableView:self.mainTableView];
    }
    
    BorkerCellModel *data = [seachDataArray objectAtIndex:indexPath.row];
    
    
    [cell.contentMoveView setTag:indexPath.row];
    
    [cell setIsEditMode:self.isEditMode];
    
    cell.data = data;
    cell.btnDelegate = self;
    
    return cell;
}

-(void)hideSearchView
{
    self.seachField.text = @"";
    [self.seachField resignFirstResponder];
    self.isSearchType = NO;
    self.seachDataArray = nil;
    self.keyword = @"*";
    
    
    [self.cacelBtn setTitle:@"" forState:UIControlStateNormal];
    self.cacelBtn.enabled = NO;
    
//    [self.seachView hide];
}


-(void)didSelecteItemIndex:(int)index{
    
    
}

#pragma mark 批量操作提交数据,staut 0:表示要启用操作，1表示要禁用操作
-(void)updateMultiOperateWithStauts:(NSString *)stauts withBorkerIds:(NSString *)brokerIds
{
    [MBProgressHUD showMessage:@"请稍等" toView:self.view];
    
    __weak typeof(self)bself = self;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        ResulteMod *mod = [dataMange batchmodifyuserstatusWithBorkerId:brokerIds withStatuts:stauts];
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [MBProgressHUD hideHUDForView:bself.view animated:YES];
            [bself.footerView.selectAllBtn setImage:[UIImage imageNamed:@"fuxuan_birder"] forState:UIControlStateNormal];
            if (mod.resltState == ResultFail) {
                
                [MBProgressHUD showError:mod.resultTip];
            }else if (mod.resltState == ResultNetError)
            {
                [MBProgressHUD showError:@"网络错误"];
            }
            else
            {
                [MBProgressHUD showSuccess:@"操作成功"];
                [bself refreshData];
            }
            
        });
    });

}


#pragma mark 获取被选中的客户的ID
-(NSString *)getSeletedCustomerIds
{
    NSMutableArray *idArrM = [NSMutableArray array];
    
    
    for (BorkerCellModel  *model in dataArray) {
        
        if (model.isSelected) {

            [idArrM addObject:model.brokerId];
        }
    }
    if (idArrM.count == 0) {
        return @"NO";
    }
    return [idArrM componentsJoinedByString:@","];
}



#pragma mark footerMuenVIew的代理(全选）
-(void)footerMenuViewSelectAllBtnOnClicked
{
    self.isSeletedAll = !self.isSeletedAll;
    NSMutableArray *arrM = [[NSMutableArray alloc]init];
    for (BorkerCellModel *model in dataArray) {
        model.isSelected = self.isSeletedAll;
        [arrM addObject:model];
    }
    self.dataArray = [[NSMutableArray alloc]initWithArray:arrM];
    [self.mainTableView reloadData];
    self.btnType = selectAllBtn;
}

#pragma mark footerMuenVIew的代理(启用）
-(void)footerMenuViewBeAbleBtnOnClicked
{
    if ([[self getSeletedCustomerIds] isEqualToString:@"NO"]) {
        [MBProgressHUD showError:@"请至少选择一个客户"];
        return;
    }
    
    [self updateMultiOperateWithStauts:@"0" withBorkerIds:[self getSeletedCustomerIds]];
    footerView.selectAllBtn.highlighted = NO;
    self.btnType = beAbleBtn;
    
}

#pragma mark footerMuenVIew的代理(禁用）
-(void)footerMenuViewbeUnAbleBtnOnClicked
{
    if ([[self getSeletedCustomerIds] isEqualToString:@"NO"]) {
        [MBProgressHUD showError:@"请至少选择一个客户"];
        return;
    }
    
    [self updateMultiOperateWithStauts:@"1" withBorkerIds:[self getSeletedCustomerIds]];
    self.btnType = beUnAbleBtn;
}
#pragma mark footerview的代理 移动按钮(批量移动）
-(void)footerMenuViewbeMoveBtnOnClicked;
{
    if ([[self getSeletedCustomerIds] isEqualToString:@"NO"]) {
        [MBProgressHUD showError:@"请至少选择一个客户"];
        return;
    }
    __weak typeof(self)bself = self;
    
    SelecteStoreVc *vc = [[SelecteStoreVc alloc]initWithBlock:^(NearbyCellData *data) {
        
        [bself refreshData];
         [bself.footerView.selectAllBtn setImage:[UIImage imageNamed:@"fuxuan_birder"] forState:UIControlStateNormal];
        
    }];
    
    vc.borkerIds = [self getSeletedCustomerIds];
    vc.vcType = BathMoveStore;
     vc.hidesBottomBarWhenPushed = YES;;
    [self.navigationController pushViewController:vc animated:YES];
}



#pragma mark brokercell的代理，处理“编辑，移动，禁用按钮ß
-(void)brokerCellFuntionBtnOnClickedWithBtn:(UIButton *)btn WithModel:(BorkerCellModel *)model
{
    switch (btn.tag) {
        case 101: //编辑
        {
            EditBrokerVC *vc = [EditBrokerVC new];
            vc.model = model;
             vc.hidesBottomBarWhenPushed = YES;;
            [self.navigationController pushViewController:vc animated:YES];
        }
                   break;
        case 102://禁用，启用
        {
            [self modifYuserstatus:model];
        }

            break;
        case 103://移动
        {
            __weak typeof(self)bself = self;
            
            SelecteStoreVc *vc = [[SelecteStoreVc alloc]initWithBlock:^(NearbyCellData *data) {
                
                [bself refreshData];
            }];
            
           vc.selectedFlag = model.storeName;
            vc.model = model;
            vc.vcType = BrokerManageVcType;
             vc.hidesBottomBarWhenPushed = YES;;
            [self.navigationController pushViewController:vc animated:YES];
        }
            
            break;
            
        default:
            break;
    }
}


-(void)modifYuserstatus:(BorkerCellModel *)model
{
    [MBProgressHUD showMessage:@"请稍等" toView:self.view];
    
    __weak typeof(self)bself = self;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        ResulteMod *mod = [dataMange modifyuserstatusWithModel:model];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [MBProgressHUD hideHUDForView:bself.view animated:YES];
            
            if (mod.resltState == ResultFail) {
                [MBProgressHUD showError:mod.resultTip];
            }else if (mod.resltState == ResultNetError)
            {
                [MBProgressHUD showError:@"网络错误"];
            }else
            {
                [MBProgressHUD showSuccess:@"操作成功"];
                
                [bself refreshData];
            }
            
            
        });
    });
    
}


#pragma mark textField的代理
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    self.seachField.text = @"";
    [textField resignFirstResponder];
    self.isSearchType = NO;
    [self.seachView hide];
    self.keyword = @"*";
    [self.cacelBtn setTitle:@"" forState:UIControlStateNormal];
    self.cacelBtn.enabled = NO;
    
    return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
{
    
    NSLog(@"关键字 %@",string);
        
    if (!self.isSearchType) {
        return YES;
    }
    NSMutableString *keyStr = [NSMutableString stringWithString:textField.text];
    
    if(![StringTool isBlankString:string])
    {
        [keyStr appendString:string];
    }else
    {
        NSUInteger length = keyStr.length - 1;
        
        NSRange rang =  NSMakeRange(0, length);
        
        keyStr =  [NSMutableString stringWithString:[keyStr substringWithRange:rang]];
    }
    
    self.keyword = keyStr;
    if(self.keyword.length >= 2)
    {
        [self searchRefreshData];
        
        [self.seachView tableViewReloadAndUpFrame];
    }
    
    return true;
}


- (void)textFieldDidBeginEditing:(UITextField *)textField{
    
    if (dataArray.count == 0 ||dataArray == nil) {
        return;
    }
    
    [self.cacelBtn setTitle:@"取消" forState:UIControlStateNormal];
    self.cacelBtn.enabled = YES;
   
    self.isSearchType = YES;
    [self.seachView show];
    
    [self.seachView tableViewReloadAndUpFrame];
    
}
- (IBAction)clickCancelBtn:(id)sender {
    
    self.keyword = @"********";
    [self.searchTv resignFirstResponder];
    [self.cacelBtn setTitle:@"" forState:UIControlStateNormal];
    self.cacelBtn.enabled = NO;
    [self.searchTv setText:@""];
    [self.searchTv textDicChange:@""];;
    [self.seachView hide];
     self.seachDataArray = nil;

}


- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
{
    if (dataArray.count == 0 ||dataArray == nil) {
        return YES;
    }
    
    [self.searchTv textDicChange:@""];
    
    [self.cacelBtn setTitle:@"取消" forState:UIControlStateNormal];
    self.cacelBtn.enabled = YES;
    
    self.isSearchType = YES;
    [self.seachView show];
    
    [self.seachView tableViewReloadAndUpFrame];
    return YES;
}
- (void)textViewDidChange:(UITextView *)textView;
{
    [self.searchTv textDicChange:textView.text];
    NSCharacterSet *set = [NSCharacterSet whitespaceAndNewlineCharacterSet];
    NSString *trimedString = [textView.text stringByTrimmingCharactersInSet:set];
    
    self.keyword = textView.text;
    if (trimedString.length == 0) {
        self.keyword = @"***********";
        
    }
    [self searchRefreshData];
     [self.seachView tableViewReloadAndUpFrame];
    
}

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text
{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        [self.searchTv setText:@""];;
        [self.searchTv textDicChange:@""];
        [self.seachView hide];
        
        self.seachDataArray = nil;
        [self.cacelBtn setTitle:@"" forState:UIControlStateNormal];
        self.cacelBtn.enabled = NO;

    }
     self.keyword = @"***********";
    return YES;
}


#pragma mark menuScroTableView delegate

-(void)cellMenDidHide:(UITableView*)tableView  cell:(ScroDeleteCell*)cell{

    BrokerCell *brokerCell = (BrokerCell *)cell;
    [brokerCell.brokerView.rightBtn setImage:[UIImage imageNamed:@"right_back_shift"] forState:UIControlStateNormal];
}


-(void)cellMenDidShow:(UITableView*)tableView cell:(ScroDeleteCell*)cell{
    BrokerCell *brokerCell = (BrokerCell *)cell;
    [brokerCell.brokerView.rightBtn setImage:[UIImage imageNamed:@"right_jiantou2"] forState:UIControlStateNormal];

}


@end
